package com.manlitech.cloudboot.oauth.config.handler;

import com.alibaba.fastjson.JSONObject;
import com.manlitech.cloudboot.common.enums.ResultEnums;
import com.manlitech.cloudboot.common.utils.Result;
import com.manlitech.cloudboot.common.utils.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 退出成功
 * @author shensg
 * @date 2021/7/7 17:46
 */
@Component
@Slf4j
public class MyLogoutSuccessHandler implements LogoutSuccessHandler {

    @Override
    public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
        httpServletResponse.setContentType("application/json;charset=utf-8");
        PrintWriter out = httpServletResponse.getWriter();
        Result result = ResultUtil.success(ResultEnums.SUCCESS_LOGOUT.getCode(),ResultEnums.SUCCESS_LOGOUT.getMsg());
        log.info(JSONObject.toJSONString(result));
        out.write(JSONObject.toJSONString(result));

    }
}